package net.mukia.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import net.mukia.model.Account;
import net.mukia.model.AccountToken;
import net.mukia.model.RToken;
import net.mukia.repository.AccountRepository;
import net.mukia.repository.AccountTokenRepository;
import net.mukia.service.AccountService;

@Service("accountService")
public class AccountServiceImpl implements AccountService {

	@Override
	public List<Account> queryAll(Account account) {
		return accountRepository.selectAll(account);
	}

	@Override
	public Account queryAccountByToken(RToken rToken) {
		Account returnObj = null;
		AccountToken accountToken = new AccountToken();
		accountToken.setrToken(rToken);
		List<AccountToken> accountTokenList = accountTokenRepository.selectAll(accountToken);
		if (null != accountTokenList && accountTokenList.size() > 0) {
			returnObj = accountTokenList.get(0).getAccount();
		}
		return returnObj;
	}

	@Override
	public void saveAccount(Account account) {
		accountRepository.insert(account);
	}
	
	@Override
	public void saveAccountToken(AccountToken accounToken) {
		accountTokenRepository.insert(accounToken);
	}

	@Resource
	private AccountRepository accountRepository;

	@Resource
	private AccountTokenRepository accountTokenRepository;

	public void setAccountRepository(AccountRepository accountRepository) {
		this.accountRepository = accountRepository;
	}

	public void setAccountTokenRepository(AccountTokenRepository accountTokenRepository) {
		this.accountTokenRepository = accountTokenRepository;
	}

}
